<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>后台管理-登录</title>
    <link rel="stylesheet" th:href="@{/static/css/login2.css}">
    <!--公共模块-->
    <div th:replace="~{layout}"></div>
</head>
<body>
<div id="container">
    <div></div>
    <div class="admin-login-background">
        <div class="admin-header">
            <span>后台管理系统</span>
        </div>
        <form class="layui-form" action="">
            <div>
                <i class="layui-icon layui-icon-username admin-icon"></i>
                <input type="text" name="username" placeholder="请输入用户名" autocomplete="off"
                       class="layui-input admin-input admin-input-username" value="guest">
            </div>
            <div>
                <i class="layui-icon layui-icon-password admin-icon"></i>
                <input type="password" name="password" placeholder="请输入密码" autocomplete="off"
                       class="layui-input admin-input" value="123456">
            </div>
            <div>
                <input type="text" name="captcha" id="captcha" placeholder="请输入验证码" autocomplete="off"
                       class="layui-input admin-input admin-input-verify">
                <img  onClick="this.src=this.src+'?'+Math.random();" id="img" class="admin-captcha" width="90" height="40" th:src="@{/sys/getVerify}">
            </div>
            <button class="layui-btn admin-button" lay-submit="" lay-filter="login">登 陆</button>
        </form>
    </div>
</div>
<script>
    layui.use(function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;

        // 进行登录操作
        form.on('submit(login)', function (data) {
            data = data.field;
            if (data.captcha == '') {
                layer.msg('请输入验证码');
                return false;
            }
            if (data.username == '') {
                layer.msg('用户名不能为空');
                return false;
            }
            if (data.password == '') {
                layer.msg('密码不能为空');
                return false;
            }

            $.ajax({
                type: 'POST',
                url: ctx + 'sys/user/login',
                dataType: "JSON",
                data: JSON.stringify(data),
                contentType: "application/json",
                success: function (res) {
                    if (res.code == 0) {
                        layer.msg('登录成功', {time: 1000}, function () {
                            window.location = ctx + 'index/home';
                        });
                    } else {
                        layer.msg(res.msg);
                        $("#img").click();
                    }
                }
            })

            return false;
        });
    });
</script>
</body>
</html>
